#version 450

layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec3 inNormal;

layout (binding = 0) uniform UBO 
{
	mat4 proj;
	mat4 view;
	mat4 model;
	vec3 scale;
} ubo;

layout (location = 0) out vec4 outColor;

const vec3 la = vec3(0.3);
const vec3 ld = vec3(0.5);
const vec3 ls = vec3(0.1);

const vec3 ka = vec3(1.0, 1.0, 1.0);
const vec3 ks = vec3(1.0, 1.0, 1.0);
const float shininess = 1.0;

void main() {
	vec3 baseColor = vec3(0.0, 1.0, 1.0);
    vec3 N = normalize(inNormal);

    vec3 lightPos = -ubo.view[3].xyz;
    vec3 s = normalize(lightPos - inPosition);
    vec3 v = normalize(-inPosition);
    vec3 r = reflect(-s, N);

    float dotSN = max(dot(s, N), 0.0);
    vec3 ambient = la * ka;
    vec3 diffuse = ld * baseColor * dotSN;
    vec3 specular = vec3(0.0);
    if( dotSN > 0.0 )
        specular = ls * ks * pow(max(dot(r,v), 0.0), shininess);

    outColor = vec4(diffuse + ambient + specular, 1.0);
}

